/*
 * @Description:小球
 * @Author: maskMan
 * @LastEditTime: 2024-03-20 19:47:16
 */
import { _decorator, Component, Vec3, v3 } from "cc";
import { Constants } from "./utils/constants";
const { ccclass, property } = _decorator;

@ccclass("ball")
export class ball extends Component {
  jumpSpeed: number = Constants.BALL_SPEED;
  lastPosY = null;
  start() {
    this.lastPosY = -5.2;
  }
  _tempPos: Vec3 = v3();
  update(dt: number) {
    if (this._tempPos.y <= this.lastPosY) {
      this.jumpSpeed = Constants.BALL_SPEED;
    }
    this.jumpSpeed -= Constants.BALL_SPEED * 3 * dt;
    this.node.getPosition(this._tempPos);
    this._tempPos.y += this.jumpSpeed * dt;
    this.node.setPosition(this._tempPos);
    if (this.jumpSpeed < 0 && this._tempPos.y - this.lastPosY <= 3) {
      this.lastPosY += 3;
    }
  }
}
